// pages/rightsMgt/rootEmployees/rootEmployees.js
import Common from '../../../common/common.js';
import config from '../../../config.js';
let common = new Common;
const app = getApp();
Page({
  data: {
    userListTransform: [],//流失转化的数组
    type: 0,
    page: 1,
    userList: [],
    userListLength: 0,
    items: [],
    hide: true,
    shopInfo: {},
    keyWords: '',
    userType: '', //列表进入人员身份
    indexUserType: '', //登录人身份
    page: 1,
    idList: '', //选择用户id
    id: '', //业务员id
    stroeInfo: {},
    userInfo: {},
    sort: 'asc', //成交额排序
    active: 0, //判断是否选中
    bdstatus: 'asc', //绑定状态排序
    on: 0,
    array: ['重新分配业务员', '流失会员申请转化', '卡券发放', '添加服务记录', '查看卡券记录'],
    array1: ['', '流失会员申请转化', '卡券发放', '添加服务记录', '查看卡券记录'],
    authoritylist: ['', '流失会员申请转化', '添加服务记录', '查看卡券记录'], //无会员管理权限
    // array: ['重新分配业务员', '流失会员申请转化', '添加服务记录', '查看卡券记录'],
    // array1: ['', '流失会员申请转化', '添加服务记录', '查看卡券记录'],
    // authoritylist: ['', '流失会员申请转化', '添加服务记录', '查看卡券记录'], //无会员管理权限
    index: 0,
    hidden: true, //筛选弹框 
    productList: [{
      goodsTypeId: 1,
      goodsTypeName: '黄金会员'
    }, {
      goodsTypeId: 2,
      goodsTypeName: '铂金会员'
    }, {
      goodsTypeId: 3,
      goodsTypeName: '钻石会员'
    },],
    productId: null, //筛选商品系列
    setcolorstatus: null, //绑定状态
    setcolorNum: null, //价格区间
    setcolor: null, //设置颜色
    productType: '', //筛选状态//
    productTypeList: [{
      id: 1,
      name: '强绑定'
    },
    {
      id: 2,
      name: '弱绑定'
    },
    {
      id: 3,
      name: '已流失'
    },
    ],
    productNum: '', //筛选库存数量
    productNumList: [{
      id: 1,
      name: '0-1000'
    },
    {
      id: 2,
      name: '1000-3000'
    },
    {
      id: 3,
      name: '3000-10000'
    },
    {
      id: 4,
      name: '超过10000'
    },
    ],
    beginNum: '', //开始数量
    endNum: '', //结束数量

    beginNumVal: '', //开始数量
    endNumVal: '', //结束数量

    vieLealCenter: '', //会员等级中转 
    bdStatusCenter: '', //绑定关系中转
    vieLeal: '', //会员等级
    bdStatus: '', //绑定关系
    priceBeginNum: '', //价格开始区间
    priceEndNum: '', //价格结束区间
    checkedAll: false, //全选
    pickerNum: '', //picker选择值
    popup: false,
    dateTiem: '请选择时间',
    serveType: [{
      id: 3,
      name: '节日关怀'
    },
    {
      id: 2,
      name: '客户拜访'
    },
    {
      id: 1,
      name: '品鉴会'
    },
    {
      id: 4,
      name: '发券'
    },
    {
      id: 5,
      name: '产品推荐'
    },
    ],
    serveInput: '', //自定义服务类型输入
    textArea: "", //服务描述
    serviceType: '',
    serviceTypeCenter: '',
    times: "00:00:00",
    accessMode: '', //从不同页面进入 1是从经营数据中进入
    bdstatusList: [1, 2, 3], //绑定关系
    isEnd: false, //是否到底
    authority: 1, //上一页店员拥有的权限 0 有卡券发放的权限
    bottomVal: 65, //获取焦点/失去焦点操作添加服务记录文本域兼容
    hideEdit: true,
    remarkName: '',
    isIphoneX: '', //判断是否是iphonex
    loadingShow: true,
  },
  // 备注弹窗
  editInfor: function (e) {
    this.setData({
      hideEdit: false,
      remarkName: e.currentTarget.dataset.remarkname || e.currentTarget.dataset.username,
      memberId: e.currentTarget.dataset.memberid
    })
  },
  // 编辑个人姓名
  noteName: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.id == 0) {
      this.setData({
        hideEdit: true
      })
    } else {
      let data = {
        memberId: this.data.memberId,
        orgSeq: this.data.orgSeq,
        remarkName: this.data.remarkName,
      }
      common.requestAjax('/api/member-service/v1/member/updateName', 'post', data).then(res => {
        if (res.data.code == 1) {
          this.setData({
            hideEdit: true
          })
          this.getUserList(1, 1);
        } else {
          common.showToast(res.data.message)
        }
      }).catch(err => {
        console.log(err);
      })
    }
  },
  // 隐藏备注
  hiddenClick: function () {
    this.setData({
      hideEdit: true
    })
  },
  // 备注名字
  bindremarkName: function (e) {
    this.setData({
      remarkName: e.detail.value
    })
  },
  // 获取焦点设置添加服务记录文本域兼容
  foucusKeyInput: function (e) {
    this.setData({
      bottomVal: 20
    })
    console.log(this.data.bottomVal)
  },
  // 失去焦点设置添加服务记录文本域兼容
  blurKeyInput: function (e) {
    this.setData({
      bottomVal: 80
    })
  },
  // 重新分配业务员
  reallocation: function () {
    this.setData({
      pickerNum: 0,
      type: 1,
    })
  },
  // 自定义服务类型输入
  serveInputs: function (e) {
    this.setData({
      inputValue: e.detail.value,
      productType: '',
    })
    console.log(this.data.inputValue)
    console.log(this.data.productType)
  },
  // 服务描述
  bindTextArea: function (e) {
    console.log(e.detail.value)
    this.setData({
      textArea: e.detail.value
    })
    console.log(this.data.textArea)
  },
  dateTiem: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      dateTiem: e.detail.value,
    })
  },
  // 点击服务类型
  serveType: function (e) {
    console.log(e.currentTarget.dataset.servicetype)
    let productType = e.currentTarget.dataset.producttype;
    let serviceType = e.currentTarget.dataset.servicetype;
    console.log(e)
    if (this.data.productType == productType) {
      this.setData({
        productType: '',
        serviceType: ''
      })
    } else {
      this.setData({
        productType: productType,
        serviceTypeCenter: serviceType,
        setcolorstatus: 1,
        inputValue: '',
      })
    }
  },
  // 添加服务记录 
  operation: function (e) {
    if (e.currentTarget.dataset.id == 1) { //1是点击确定   
      console.log(this.data.dateTiem)
      console.log(this.data.dateTiem + this.data.times)
      console.log(this.data.serviceTypeCenter)
      // 时间为空
      if (this.data.dateTiem == '请选择时间' || this.data.dateTiem == '') {
        common.showToast('请选择时间');
        return
      }
      console.log(this.data.inputValue)
      // 服务类型为空
      if (this.data.inputValue) {
        this.setData({
          serviceTypeCenter: this.data.inputValue
        })
      } else {
        if (this.data.serviceTypeCenter == '') {
          common.showToast('请选择服务类型');
          return
        }
      }
      if (!this.data.textArea) {
        common.showToast('请填写服务描述');
        return
      }
      // console.log(getApp().globalData.userId)
      // return;
      let data = {
        userId: getApp().globalData.userId,
        memberIds: this.data.idList,
        orgSeq: this.data.orgSeq,
        serviceType: this.data.serviceTypeCenter, //服务类型
        serviceDesc: this.data.textArea, //服务描述
        createTime: this.data.dateTiem + ' ' + this.data.times // 服务时间
      }
      common.requestAjax('/api/member-service/v1/memberApplyRecord/increaseServiceRecord', 'put', data).then(res => {
        if (res.data.code == 1) {
          common.showToast(res.data.message)
          this.setData({
            popup: false,
            type: 0
          })
          this.getInfo();
          // this.getUserList();
          // this.queryGradelevelRule();//查询分类
        } else {
          common.showToast(res.data.message)
        }
      }).catch(err => {
        console.log(err);
      })
    } else { //0是取消添加服务记录
      this.setData({
        popup: false
      })
    }

  },
  // 获取tab下标 设置颜色
  // setcolor: function(e) {
  //   this.setData({
  //     setcolor: e.currentTarget.dataset.type
  //   })
  // },
  // 开始数量
  beginNum: function (e) {
    this.setData({
      beginNum: e.detail.value,
      productNum: ''
    })
  },
  // 结束数量
  endNum: function (e) {
    this.setData({
      endNum: e.detail.value,
      productNum: ''
    })
  },
  // 点击商品系列分类
  product: function (e) {
    console.log(e);
    let productId = e.currentTarget.dataset.product;
    let vieLeal = e.currentTarget.dataset.vieleal;
    if (this.data.productId == productId) {
      this.setData({
        productId: '',
        vieLeal: '',
        vieLealCenter: ''
      })
    } else {
      this.setData({
        productId: productId,
        setcolor: 0,
        vieLealCenter: vieLeal
      })
    }
  },
  // 点击商品类型
  productType: function (e) {
    let productType = e.currentTarget.dataset.producttype;
    let bdStatus = e.currentTarget.dataset.bdstatus;
    console.log(e)
    if (this.data.productType == productType) {
      this.setData({
        productType: '',
        bdStatus: '',
        bdStatusCenter: ''
      })
    } else {
      let bdstatusList = this.data.bdstatusList;
      bdstatusList.push(e.currentTarget.dataset.producttype)
      this.setData({
        productType: productType,
        bdStatusCenter: bdStatus,
        setcolorstatus: 1,
        bdstatusList: bdstatusList
      })
    }
  },
  // 点击商品数量
  productNum: function (e) {
    let productNum = e.currentTarget.dataset.productnum;
    this.setData({
      beginNumVal: '',
      endNumVal: '',
      beginNum: '',
      endNum: '',
      priceBeginNum: '',
      priceEndNum: '',
    })
    if (this.data.productNum == productNum) {
      this.setData({
        productNum: ''
      })
    } else {
      // 1 0-1000  2 1000-3000 3 3000-10000  4 10000
      if (productNum == 1) {
        this.setData({
          beginNum: 0,
          endNum: 1000,
        })
      } else if (productNum == 2) {
        this.setData({
          beginNum: 1000,
          endNum: 3000,
        })
      } else if (productNum == 3) {
        this.setData({
          beginNum: 3000,
          endNum: 10000,
        })
      } else {
        this.setData({
          beginNum: 10000,
          endNum: 100000,
        })
      }
      if (this.data.endNum == 100000) {
        this.setData({
          beginNum: '超过',
          endNum: 100000,
        })
      }
      this.setData({
        productNum: productNum,
        beginNum: this.data.beginNum,
        endNum: this.data.endNum,
        setcolorNum: 2,
      })
    }

  },
  // 点击显示弹框
  showMask: function (e) {
    this.setData({
      hidden: false,
      bdstatusList: []
    })
  },
  // 弹框取消/确定按钮
  hideMask: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.no == 2) {
      this.setData({
        hidden: true,
      })
      return
    }
    if (e.currentTarget.dataset.no == 0) {
      this.setData({
        productId: '',
        productType: '',
        productNum: '',
        priceBeginNum: '',
        priceEndNum: '',
        vieLeal: '',
        bdStatus: '',
        beginNum: '', //开始数量
        endNum: '', //结束数量
        beginNumVal: '', //开始数量
        endNumVal: '', //结束数量
        vieLealCenter: '', //会员等级中转 
        bdStatusCenter: '', //绑定关系中转
        vieLeal: '', //会员等级
        bdStatus: '', //绑定关系
      })
    } else {
      if (this.data.beginNum && this.data.endNum) {
        this.setData({
          setcolorNum: 2,
        })
      } else {
        // wx.showToast({
        //   title: '请选择或输入价格区间',
        //   icon:'none'
        // })
        // return;
      }
      if (this.data.beginNum > this.data.endNum) {
        wx.showToast({
          title: '开始价格不能高于结束价格',
          icon: 'none'
        })
        return;
      }
      if (this.data.beginNum > 10000 || this.data.beginNum > 10000) {
        this.setData({
          beginNum: '超过',
          endNum: '10000',
        })
      }
      this.setData({
        priceBeginNum: !this.data.beginNum ? this.data.priceBeginNum : this.data.beginNum, //价格开始区间
        priceEndNum: !this.data.endNum ? this.data.priceEndNum : this.data.endNum, //价格结束区间
        vieLeal: !this.data.vieLealCenter ? this.data.vieLeal : this.data.vieLealCenter, //会员等级
        bdStatus: !this.data.bdStatusCenter ? this.data.bdStatus : this.data.bdStatusCenter, //绑定关系
        hidden: true,
        page: 1, //页面默认第一页
        userList: [], //筛选先置空列表
      });
      this.getUserList(1, 1)
    }
  },
  // 选择底部弹框
  bindPickerChange: function (e) {

    console.log('picker发送选择改变，携带值为', e.detail.value);
    this.setData({
      pickerNum: e.detail.value,
    })

    // 判断选择卡券发放权限设置
    if (this.data.indexUserType != 6) {
      if (e.detail.value == 0) {
        this.setData({
          type: 1,
        })
      } else if (e.detail.value == 1) {

        //筛选已经被转化的人
        let array = this.data.userList.filter((item) => {
          return item.bdstatus == 3 && item.bdship == 3;
        });

        this.setData({
          type: 1,
          userListTransform: array
        })

      } else if (e.detail.value == 2) {
        this.setData({
          type: 1,
        })
      } else if (e.detail.value == 3) {
        // 添加服务记录
        let employeeName = this.data.userInfo.realName
        console.log(employeeName)
        wx.navigateTo({
          url: '/pages/couponsMgt/couponsRecord/index?employeeName=' + employeeName,
        })

      }
    } else {
      if (e.detail.value == 0) {
        this.setData({
          type: 0,
        })
      } else if (e.detail.value == 1) {
        //筛选已经被转化的人
        let array = this.data.userList.filter((item) => {
          return item.bdstatus == 3 && item.bdship == 3;
        });

        this.setData({
          type: 1,
          userListTransform: array
        })
      } else if (e.detail.value == 2) {
        this.setData({
          type: 1,
          pickerNum: 2
        })
      } else if (e.detail.value == 3) {
        let employeeName = this.data.userInfo.realName
        console.log(employeeName)
        wx.navigateTo({
          url: '/pages/couponsMgt/couponsRecord/index?employeeName=' + employeeName,
        })
      }

    }
  },
  // 返回上一页
  navback: function () {
    wx.navigateBack()
  },
  // 多选框事件
  checkboxChange: function (e) {
    this.setData({
      idList: e.detail.value
    })
    console.log(this.data.idList)
  },
  //流失转化单选
  checkOneboxChange(e) {
    this.setData({
      transformID: e.detail.value
    })
  },
  // 单选框事件
  radioChange: function (e) {
    this.setData({
      id: e.detail.value
    })
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  checkboxChangeAll: function (e) {
    var that = this;
    // if (that.data.pickerNum==0){
    //   let userList = that.data.userList.filter(item => {
    //     return item.bdstatus != 3
    //   })
    //   console.log(userList)
    //   that.setData({
    //     userList: userList
    //   })
    // }
    for (let i = 0; i < that.data.userList.length; i++) {
      // 判断业务员分配（强绑定、弱绑定）全选过滤 / 卡券发放全选过滤
      // if (that.data.pickerNum == 0 || that.data.pickerNum == 2 || that.data.pickerNum == 3) {
      //   if (that.data.userList[i].bdstatus != 3) {
      //     that.data.userList[i].checked = (!that.data.checkedAll)
      //   }
      // }
      if (that.data.pickerNum == 0) {
        if (that.data.userList[i].bdstatus != 3) {
          that.data.userList[i].checked = (!that.data.checkedAll)
        }
      }
      // 判断流失会员申请转化
      if (that.data.pickerNum == 1) {
        if (that.data.userList[i].bdstatus == 3) {
          if (that.data.userList[i].bdship == 3) {
            that.data.userList[i].checked = (!that.data.checkedAll)
          }
        }
      }
      // that.data.userList[i].checked = (!that.data.checkedAll)
    }
    let idList = [];
    for (let j = 0; j < that.data.userList.length; j++) {
      if (that.data.userList[j].checked == true) {
        idList.push(that.data.userList[j].memberId)
      }
    }
    that.setData({
      userList: that.data.userList,
      checkedAll: (!that.data.checkedAll),
      idList: idList,
    })
    console.log(idList)
    console.log(that.data.checkedAll)
  },
  // 选择分配的用户 取消按钮
  cancleAuth: function (e) {
    let userList = this.data.userList.map(item => {
      if (item.checked == true) item.checked = false;
      return item
    })
    this.getUserList(1, 1)
    this.setData({
      type: 0,
      // idList: [],
      // checkedAll: false,
      // userList: userList
    })
  },
  // 选择用户
  changePeople: function (e) {
    console.log(e)
    let type = e.currentTarget.dataset.type;
    this.setData({
      type: 1
    })
  },
  // 选择指派业务员
  changePeopleset: function (e) {

    // 重新分配业务员
    if (this.data.pickerNum == 0) {
      if (!this.data.idList || this.data.idList.length == 0) {
        wx.showToast({
          title: '请选择用户',
          icon: 'none'
        })
        return;
      }
      let type = e.currentTarget.dataset.type;
      this.setData({
        type: type,
        hide: false
      })
      this.queryStoreUsers();
    } else if (this.data.pickerNum == 9) {
      // 卡券发放
      if (!this.data.idList || this.data.idList.length == 0) {
        wx.showToast({
          title: '请选择用户',
          icon: 'none'
        })
        return;
      }
      wx.navigateTo({
        url: '/pages/couponsMgt/couponsIssue/sureCoupons/index?memberList=' + this.data.idList,
      })
    } else if (this.data.pickerNum == 1) {
      console.log(1)
      if (!this.data.transformID) {
        wx.showToast({
          title: '请选择用户',
          icon: 'none'
        })
        return;
      }
      wx.showModal({
        title: '提示',
        content: '您选的有会员，需要消费达到一定金额才能转化；转化时长7天，超期自动回到公有池',
        success: (res) => { // 流失会员转化申请接口请求
          if (res.confirm) { //用户点击确定   
            let that = this;
            //if (that.data.pickerNum == 1) {

            let data = {
              userId: getApp().globalData.userId,
              memberId: that.data.transformID,
              orgSeq: that.data.orgSeq,
            }

            common.requestAjax('/api/member-service/v1/memberApplyRecord/memberTransformApply', 'put', data).then(res => {
              if (res.data.code == 1) {
                wx.showToast({
                  title: '添加流失会员转化记录成功',
                  icon: 'none'
                })
                this.setData({
                  type: 0
                })
                this.getUserList(1, 1)
                this.getInfo();
              } else {
                wx.showToast({
                  title: res.data.message,
                  icon: 'none'
                })
              }
            }).catch(err => {
              console.log(err);
            })

          } else if (res.cancel) {
            console.log('用户点击关闭')
          }
        }
      })
    } else if (this.data.pickerNum == 2) { // 添加服务记录
      if (!this.data.idList) {
        wx.showToast({
          title: '请选择用户',
          icon: 'none'
        })
        return;
      }
      let dateTiem = this.data.dateTiem;
      if (dateTiem != '请选择时间') {
        this.setData({
          dateTiem: '请选择时间',
        })
        console.log(this.data.dateTiem + '111')
        console.log(this.data.textArea + '222')
      }


      this.setData({
        inputValue: '',
        serviceTypeCenter: '',
        productType: '',
        serviceType: '',
        textArea: '',

        popup: true,
      })
    }
  },
  // 搜索条件查询
  bindKeyInput: function (e) {
    this.setData({
      keyWords: e.detail.value
    })
    this.getUserList(1, 1)
  },
  // 会员列表
  getUserList(page, type) { 
    let data = {}
    if (this.data.priceBeginNum == '超过') {
      this.setData({
        priceBeginNum: 10001,
        priceEndNum: 10001,
      })
    }
    
    if (this.data.userType == 4 || this.data.userType == 5) {
      data = {
        condition: {
          orgSeq: this.data.orgSeq,
          userId: '',
          keyWords: this.data.keyWords,
          gradelevelId: this.data.productId,
          bdrelationship: this.data.productType, //绑定关系 1强绑定 2弱绑定3已流失
          // bdstatusList: [1, 2, 3],
          bdstatusList: this.data.bdstatusList,
          beginSumMoney: this.data.priceBeginNum, //开始金额
          endSumMoney: this.data.priceEndNum, //结束金额
        },
        current: page,
        size: 10,
      };
    } else {
      data = {
        condition: {
          userId: this.data.userId,
          orgSeq: getApp().globalData.shopInfo.orgSeq,
          keyWords: this.data.keyWords,
          // sort: this.data.sort,
          // bdstatus: this.data.bdstatus
          gradelevelId: this.data.productId,
          bdrelationship: this.data.productType, //绑定关系 1强绑定 2弱绑定3已流失
          bdstatusList: this.data.bdstatusList,
          beginSumMoney: this.data.priceBeginNum, //开始金额
          endSumMoney: this.data.priceEndNum, //结束金额
        },
        current: page,
        size: 10,
      };
    }
    common.requestAjax('/api/member-service/v1/member/queryMembers', 'POST', data).then(res => {
      if (res.data.code == 1) { 
        this.setData({
          loadingShow: false,
        })   
        let arraylist = this.data.userList;
        let isEnd = this.data.isEnd;
        if (type == 1) {
          //下拉刷新
          arraylist = res.data.records;
          isEnd = false;
        } else if (type == 2) {
          //上拉加载
          arraylist = arraylist.concat(res.data.records);
          if (res.data.records.length == 0) {
            //最后一行没数据 到底了
            isEnd = true;
          }
          setTimeout(() => {
            wx.hideLoading()
          }, 500)
        }
        this.setData({
          userList: arraylist,
          userListLength: res.data.total, // 会员列表长度
          isEnd,
        })
        arraylist.forEach((item) => {
          item.createTime = item.createTime.substr(0, 10)   //时间转化  
        });
        this.setData({
          userList: arraylist,
        })
      } else {
        common.showToast(res.data.message)
      }
    }).catch(err => {
      console.log(err);
    })
  },
  //  业务员
  queryStoreUsers: function () {
    let data = {
      orgSeq: this.data.orgSeq,
    }

    common.requestAjax('/api/user-service/v1/user/queryStorePerson', 'POST', data).then(res => {
      if (res.data.code == 1) {
        console.log(res)
        this.setData({
          items: res.data.records
        })
      } else {
        common.showToast(res.data.message)
      }
    }).catch(err => {
      console.log(err);
    })
  },
  // 点击取消按钮
  cancle: function (e) {
    this.setData({
      id: '',
      hide: true
    })
  },
  // 提交用户指派给的业务员
  submit: function () {
    if (!this.data.id) {
      wx.showToast({
        title: '请选择业务员',
        icon: 'none'
      })
      return;
    }
    let that = this;
    wx.showModal({
      title: '提示',
      content: '确定指派给该业务员吗？',
      success(res) {
        if (res.confirm) {
          that.updateBind()
        } else if (res.cancel) {
          // that.setData({
          //   hide: true,
          //   items: []
          // })
          console.log('用户点击取消')
        }
      }
    })
  },
  // 提交配送业务员
  updateBind: function (e) {
    let data = {
      userId: this.data.id,
      memberIds: this.data.idList,
      orgSeq: this.data.orgSeq,
    }
    common.requestAjax('/api/member-service/v1/member/updateBind', 'POST', data).then(res => {
      if (res.data.code == 1) {
        wx.showToast({
          title: res.data.message,
          icon: 'none'
        })
        setTimeout(() => {
          this.setData({
            hide: true,
            type: 0
          })
          this.getUserList(1, 1)
          this.getInfo();
        }, 2000)

      } else {
        common.showToast(res.data.message)
      }
    }).catch(err => {
      console.log(err);
    })
  },
  vipDetil: function (e) {
    let memberId = e.currentTarget.dataset.id;
    let routeUrl = '/pages/rightsMgt/customerInfo/customerInfo';
    let routeType = 'navigateTo';
    let params = '?memberId=' + memberId;
    common.routeLink(routeUrl, params, routeType)
  },
  getInfo: function (e) {
    let data = {
      userId: this.data.userId,
      orgSeq: this.data.orgSeq
    }
    common.requestAjax('/api/user-service/v1/foreign/getUserAndStoreInfo', 'GET', data).then(res => {
      console.log(res)
      console.log(res.data.stroeInfo)
      this.setData({
        stroeInfo: res.data.storeInfoDTO,
        userInfo: res.data.userInfoDTO,
      })
    }).catch(err => {
      console.log(err);
    })
  },
  // 查询会员等级
  queryGradelevelRule: function (e) {
    let data = {
      "size": 999999,
      "current": 1,
      "condition": {
        "gradelevelName": ""
      },
      "ascs": [],
      "descs": []
    }
    common.requestAjax('/api/member-service/v1/GradelevelRule/queryGradelevelRule', 'POST', data).then(res => {
      console.log(res)
      this.setData({
        productList: res.data.records
      })
    }).catch(err => {
      console.log(err);
    })
  },
  // 查询用户拥有哪些权限
  getRootData() {
    let shopInfo = app.globalData.shopInfo;
    let data = {
      userType: shopInfo.userType,
      orgSeq: shopInfo.orgSeq,
      userId: app.globalData.userId,
    }
    common.requestAjax('/api/user-service/v1/detail/getAuthority', 'POST', data).then(res => {
      if (res.data.code) {
        console.log(res.data.result.authorityList)
        let authoritylist = res.data.result.authorityList;
        let aut;
        if (authoritylist) {
          authoritylist.filter(item => {
            if (item.authorityName == '卡券发放') {
              aut = 0
            }
          })
        }
        this.setData({
          authority: aut
        })
        console.log(aut)
        // this.setData({
        //   picShopList: res.data.result.authorityList
        // })
      }
    }).catch(err => {

    })
  },
  onLoad(options) {
    console.log(options)
    //员工点击直接进来
    //店长点击从管理员工页面进来 带参数
    let userType = options.userType || app.globalData.shopInfo.userType;
    let userId = options.userId || app.globalData.userId;
    let orgSeq = options.orgSeq || app.globalData.shopInfo.orgSeq;
    console.log(userType + '=====当前进来的类型====')
    this.setData({
      userType,
      userId,
      orgSeq,
      accessMode: options.accessMode,
      indexUserType: app.globalData.shopInfo.userType,
      isIphoneX: app.globalData.isIphoneX
    })
    console.log(this.data.isIphoneX)
    //从整体经营数据中进入 options.accessMode == 1
    if (this.data.accessMode == 1) {
      wx.setNavigationBarTitle({
        title: '全部会员数据' //修改title
      })
    }
    console.log(this.data.userType)
    this.getInfo();
    this.getUserList(1, 1);
    this.queryGradelevelRule(); //查询分类
    this.getRootData(); //查询用户权限
  },
  // 下拉触底时间
  onReachBottom: function () {
    if (!this.data.isEnd) {
      console.log(1)
      let pageNumber = this.data.page;
      pageNumber += 1;
      console.log(pageNumber)

      wx.showLoading({
        title: '正在加载中...',
      })
      this.setData({
        page: pageNumber
      })
      this.getUserList(pageNumber, 2)
    }



    // if (!this.data.isEnd) {
    //   var that = this
    //   that.setData({
    //     page: Number(that.data.page) + 1
    //   })
    //   this.getUserList() //会员列表
    //   wx.showLoading({
    //     title: '正在加载中...',
    //   })
    //   console.log(this.data.page)
    // }
  },
})